import yaml


class ConfigTools:

    @staticmethod
    def read_config(*keys):
        yaml_dict = []
        current_key = ""
        try:
            with open("/tmp/global.yaml") as yaml_file:
                yaml_obj = yaml.safe_load(yaml_file)
                for key in keys:
                    current_key = ""
                    key_list = key.split('.')
                    obj = yaml_obj
                    for key_item in key_list:
                        if current_key != "":
                            current_key = current_key + "."
                        current_key = current_key + key_item
                        obj = obj[key_item]
                    yaml_dict.append(obj)
        except KeyError:
            raise RuntimeError("not found key {} in global.yaml".format(current_key))

        return yaml_dict


def main():
    print(ConfigTools().read_config("dingding.robot.access_token", 'tencent.common.SecretKey', "kibana.version",
                                    "kibana.ip"))


if __name__ == '__main__':
    main()
